package top.codedance.iotp.server.net.handle.subhandle.controller.http.sync;

import com.alibaba.fastjson.JSONObject;
import top.codedance.iotp.server.ServerApplication;
import top.codedance.iotp.server.net.handle.subhandle.controller.AdapterController;

public class ClientVersionController extends AdapterController {
    public String doSubHandler(JSONObject body) {
        try {
            if (!adminVerification()) {
                return response403("No access");
            }
            Long versionCode = body.getLong("versionCode");
            ServerApplication.versionFileUtil.update(versionCode.toString());
            ServerApplication.setLastClientVersionCode(versionCode);
            return okResponse("Set success, current last version code: " + ServerApplication.getLastClientVersionCode());
        } catch (Exception e) {
            return response500("Programe exception");
        }
    }
}
